package org.example.code.contorller;

import org.example.code.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: CodeContorller
 * @author: e
 * @createDate: 2021/5/30
 */
@RequestMapping("/code")
@RestController
public class CodeContorller {

    @Autowired
    private ICodeService codeService;

    /***
     * 生成验证码并发送到对应邮箱，成功true，失败false
     **/
    @GetMapping("/create/{email}")
    public boolean create(@PathVariable("email") String email) {
        return codeService.create(email);
    }


    /***
     * 校验验证码是否正确 0 正确，1错误，2 超时
     **/
    @GetMapping("/validate/{email}/{code}")
    public int validate(@PathVariable("email") String email,
                        @PathVariable("code") String code) {
        return codeService.validate(email,code);
    }


    /***
     * 更新状态
     **/
    @GetMapping("/update/status/{code}")
    public boolean updateStatus(@PathVariable("code") String code) {
        return codeService.updateStatus(code);
    }
}
